package com.wwdx.service.impl;

import com.google.common.collect.Maps;
import com.wwdx.model.WvirtualUserModel;
import com.wwdx.service.WvirtualUserServiceI;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @author liguoliang
 */
@Service
public class WvirtualUserServiceImpl extends BaseServiceImpl<WvirtualUserModel> implements WvirtualUserServiceI{

    @Override
    public WvirtualUserModel getByUnionId(String unionid) {
        Map<String, Object> params = Maps.newHashMapWithExpectedSize(2);
        params.put("unionid",unionid);
        String hql = "from WvirtualUserModel where unionid=:unionid";
        return this.getByHql(hql,params);
    }

    @Override
    public void modifyNumber(String unionid, BigDecimal number, Integer status) {
        Map<String, Object> params = Maps.newHashMapWithExpectedSize(2);
        params.put("number",number);
        params.put("unionid",unionid);
        if (status == 0){
            this.executeSql("UPDATE w_virtual_user SET number = number+:number,modify_time=now() where unionid=:unionid",params);
        }else {
            this.executeSql("UPDATE w_virtual_user SET number = number-:number,modify_time=now() where unionid=:unionid",params);
        }
    }
}